home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z12.ADF / arcre.c < prev    next >
C/C++ Source or Header  |  1987-04-09  |  3KB  |  105 lines

  1. /*
  2.  * ARCre - Create rename scripts so that files with long names can be
  3.  *         easily put into ARChives.
  4.  *
  5.  * Here's how to use it:
  6.  *
  7.  *   ARCre [file(s) to be ARCed...]         : Create the rename scripts.
  8.  *   execute ARCre.bat                      : Rename the files to be ARCed.
  9.  *   ARC a ARChive ARCfile.* execute.me     : Create the ARChive.
  10.  *   execute execute.me                     : Rename the files back.
  11.  *
  12.  *   ARCre takes file names like the ARC program does.  (It will accept
  13.  *   the '*' wildcard.)  Two scripts are produced: "ARCre.bat" and
  14.  *   "execute.me".  The first one will rename the files to "ARCfile.#",
  15.  *   where '#' is 1,2,3,...  The second one will rename the files back
  16.  *   to their original names.
  17.  *
  18.  * Copyright (c) 1987 John R. Hoffman
  19.  *
  20.  * This program is placed in the public domain as long as the above
  21.  * copyright is included.  Sale of this program except for REASONABLE 
  22.  * media costs is prohibited.
  23.  *
  24.  * The credit for the idea for this program goes to John Foust.
  25.  *
  26.  * To create with MANX: cc ARCre.c
  27.  *                      ln ARCre.o -lc
  28.  *
  29.  */
  30.  
  31. static char *Copyright = "Copyright (c) 1987 John R. Hoffman";
  32.  
  33. #include <stdio.h>
  34.  
  35. #define RENAME1  "ARCre.bat"
  36. #define RENAME2  "EXECUTE.ME"
  37. #define BASENAME "ARCfile.%d"
  38.  
  39. FILE *fopen();
  40. char *scdir();
  41.  
  42. main(argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.     int i, fcnt;
  47.     char *cp, name[50];
  48.     FILE *fp1, *fp2;
  49.  
  50.     fp1  = NULL;
  51.     fp2  = NULL;
  52.     fcnt = 1;
  53.  
  54.     if ( argc <= 1 ) {
  55.         fprintf(stderr, "Usage: ARCre files ...\n");
  56.         exit();
  57.     }
  58.  
  59.     for ( i = 1; i < argc; i++ ) {
  60.  
  61.         while ( (cp = scdir(argv[i])) != (char *) NULL ) {
  62.  
  63.             if ( fp1 == (FILE *) NULL ) {
  64.                 if ( (fp1 = fopen(RENAME1, "w")) == (FILE *) NULL ) {
  65.                     fprintf(stderr, "ARCre: Error opening \"%s\".\n", RENAME1);
  66.                     exit();
  67.                 }
  68.             }
  69.  
  70.             if ( fp2 == (FILE *) NULL ) {
  71.                 if ( (fp2 = fopen(RENAME2, "w")) == (FILE *) NULL ) {
  72.                     fprintf(stderr, "ARCre: Error opening \"%s\".\n", RENAME2);
  73.                     if ( fp1 != (FILE *) NULL ) {
  74.                         fclose(fp1);
  75.                     }
  76.                     exit();
  77.                 }
  78.             }
  79.  
  80.             sprintf(name, BASENAME, fcnt++);
  81.  
  82.             fprintf(fp1, "rename \"%s\" %s\n", cp, name);
  83.  
  84.             fprintf(fp2, "rename %s \"%s\"\n", name, cp);
  85.  
  86.         }
  87.  
  88.     }
  89.  
  90.     if ( fcnt == 1 ) {
  91.         fprintf(stderr, "ARCre: No matching files found.\n");
  92.         exit();
  93.     }
  94.  
  95.     if ( fp1 != (FILE *) NULL ) {
  96.         fclose(fp1);
  97.     }
  98.  
  99.     if ( fp2 != (FILE *) NULL ) {
  100.         fclose(fp2);
  101.     }
  102.  
  103.     exit();
  104. }
  105.